<?php

namespace app\common\model\demo;

use app\common\model\CommonBaseModel;

class Demo extends CommonBaseModel
{
    /*
    CREATE TABLE `demo` (
      `id` int(11) NOT NULL COMMENT 'id',
      `type` int(11) NOT NULL COMMENT '类型:1类型A,2类型B',
      `name` varchar(50) NOT NULL DEFAULT '' COMMENT '名称',
      `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态:1正常,2异常',
      `is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除:0未删除,1已删除',
      `creator_id` int(11) NOT NULL COMMENT '创建人id',
      `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
      `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
      PRIMARY KEY (`id`),
      KEY `type` (`type`) COMMENT '类型'
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='demo表';
     */

    //type 类型:1类型A,2类型B
    const TYPE_A = 1;
    const TYPE_B = 2;
    const TYPE_MAP = [
        self::TYPE_A => '类型A',
        self::TYPE_B => '类型B',
    ];

    //status 状态:1正常,2异常
    const STATUS_NORMAL = 1;
    const STATUS_DISABLED = 2;
    const STATUS_MAP = [
        self::STATUS_NORMAL => '正常',
        self::STATUS_DISABLED => '已禁用',
    ];

    /**
     * 获取正常的列表
     * @return array
     */
    public static function getNormalList(){
        $where = [];
        $where[] = ['status','=',self::STATUS_NORMAL];
        return self::whereNotDelete($where)->select()->toArray();
    }

    /**
     * 更新status
     */
    public static function updateDemoStatus($id, $status){
        return self::where(['id'=>$id])->update(['status'=>$status]);
    }

}